var expire = new Date();
expire.setTime(expire.getTime()+30*24*3600*1000);

var CompareCart = function(options){
	settings = {
		maxCount : 5                //比较车最大容量，即最多可添加商品数
       };
    options = options || {};
    $j.extend(settings, options);
    
    productType = null;       //比较车的商品类型，存贮商品类型的id
	PRODUCTIDS_COOKIENAME = 'compareCart_productIds';
	PRODUCTTYPEID_COOKIENAME = 'compareCart_productTypeId';
	_ITEM_SEPERATOR = '_ITEM_SEPERATOR';
}
       	
			
CompareCart.prototype.setUp = function(){
	
}

/*
*添加或者移除商品
*productId :商品id
*productTypeId ：商品类型id
*/
CompareCart.prototype.toggleProduct = function(productId,productTypeId){

}
/*
*添加商品
*productId :商品id
*productTypeId ：商品类型id
*/
CompareCart.prototype.addProduct= function(productId,productTypeId){
	var currProductTypeId =  getCookie(PRODUCTTYPEID_COOKIENAME);
	if(currProductTypeId == null || currProductTypeId == ""){
		//比较车为空
		setCookie(PRODUCTTYPEID_COOKIENAME,productTypeId, expire, __ctxPath, null, null); 
	}else{
		//比较车已有商品
		if(currProductTypeId != productTypeId){
			//不允许添加不同类型的商品
			alert(__FMT.compareCart_productTypeNotAllow);
			return false;
		}
	}
	var currProductIds = getCookie(PRODUCTIDS_COOKIENAME);
	var currProductArray = null;
	if(currProductIds == null || currProductIds == ""){
		currProductArray = new Array();
	}else{
		currProductArray = currProductIds.split(_ITEM_SEPERATOR);
	}
	if(currProductArray.length == settings.maxCount){
		//已超过最大允许添加数
		alert(__FMT.compareCart_exceedMaxCount1+settings.maxCount+__FMT.compareCart_exceedMaxCount2);
		return false;
	}
	var index = currProductArray.indexOf(productId);
	if(index != -1){
		//已存在该商品
		return false;
	}
	
	currProductArray.push(productId);
	setCookie(PRODUCTIDS_COOKIENAME,currProductArray.toStringUsingDel(_ITEM_SEPERATOR), expire, __ctxPath, null, null); 
	return true; 
		
}
/*
*移除商品
*productId :商品id
*/
CompareCart.prototype.removeProduct= function(productId){
	var currProductIds = getCookie(PRODUCTIDS_COOKIENAME);
	var currProductArray = null;
	if(currProductIds == null || currProductIds == ""){
		return;
	}else{
		currProductArray = currProductIds.split(_ITEM_SEPERATOR);
	}
	var index = currProductArray.indexOf(productId);
	if(index == -1){
		return;
	}
	currProductArray.remove(index);
	if(currProductArray.length == 0)  {
		deleteCookie(PRODUCTTYPEID_COOKIENAME,__ctxPath);
		deleteCookie(PRODUCTIDS_COOKIENAME,__ctxPath);
	}else{
		setCookie(PRODUCTIDS_COOKIENAME,currProductArray.toStringUsingDel(_ITEM_SEPERATOR), expire,__ctxPath, null, null);
	}
}
/*
*用于比较当前商品数组与cookie是否匹配
*productIdArray
*/
CompareCart.prototype.isSame = function(productIdArray){

	if(productIdArray == null)return false;
	return productIdArray.toStringUsingDel(_ITEM_SEPERATOR) == getCookie(PRODUCTIDS_COOKIENAME);
}

/*
*更新比较车
*/
CompareCart.prototype.update= function(productTypeCookie,productIdsCookie){
	setCookie(PRODUCTTYPEID_COOKIENAME,productTypeCookie, expire, __ctxPath, null, null);  
	setCookie(PRODUCTIDS_COOKIENAME,productIdsCookie, expire, __ctxPath, null, null);  
}


/*
*清空比较车
*/
CompareCart.prototype.clear= function(productId){
	deleteCookie(PRODUCTTYPEID_COOKIENAME,__ctxPath);
	deleteCookie(PRODUCTIDS_COOKIENAME,__ctxPath);
}


/*
*添加商品到比较栏
*productId :商品id
*/
CompareCart.prototype.appendProductHTML= function(productId){
	
}
var $cc = new CompareCart();



 
 
